package cn.otrue.patienthealthmanager.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.bean.QuestionnaireListModel;
import cn.otrue.patienthealthmanager.utils.CommonUtil;

public class QuestionnaireAdapter extends BaseAdapter {
	private List<QuestionnaireListModel> questionnaireList;
	private LayoutInflater inflater;

	public QuestionnaireAdapter(Context context,
			List<QuestionnaireListModel> questionnaireList) {
		this.questionnaireList = questionnaireList;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return questionnaireList != null ? questionnaireList.size() : 0;
	}

	@Override
	public Object getItem(int arg0) {
		return questionnaireList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		HolderView holder;
		if(convertView==null){
		convertView=inflater.inflate(R.layout.questionnairelist_item, null);
		holder=new HolderView();
		holder.tv_question_list_item_content=(TextView) convertView.findViewById(R.id.tv_question_list_item_content);
		holder.tv_question_list_item_time=(TextView) convertView.findViewById(R.id.tv_question_list_item_time);
		convertView.setTag(holder);
		}else{
			holder=(HolderView) convertView.getTag();
		}
		holder.tv_question_list_item_content.setText(CommonUtil.getName(questionnaireList.get(position).doctorNickname, questionnaireList.get(position).doctorRealName, questionnaireList.get(position).account)+"给"+CommonUtil.getName(questionnaireList.get(position).PatientNickName, questionnaireList.get(position).patientRealname, questionnaireList.get(position).useraccount)+"发送了“"+questionnaireList.get(position).questionTitle+"”问卷");
		SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
		String time=null;
		Date date =new Date(questionnaireList.get(position).createtime);
		time=sdf.format(date);
		holder.tv_question_list_item_time.setText(time);
		return convertView;
	}

	class HolderView {
		public TextView tv_question_list_item_content;
		public TextView tv_question_list_item_time;
	}

}
